home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interactive Web Graphics with Shout 3D
/
Interactive Web Graphics With Shout 3D.iso
/
mac
/
Code
/
Chapter09
/
ChangeSpeedPanel.java
< prev
next >
Wrap
Text File
|
2000-10-13
|
2KB
|
80 lines
package applets;
import shout3d.*;
import shout3d.core.*;
import shout3d.math.*;
public class ChangeSpeedPanel extends Shout3DPanel implements DeviceObserver {
Transform t;
float xPos;
float speed = 0.0f; //in meters per second
float limit = 3.0f;
//screen pixels
int pixelStartY;
int pixelEndY;
public ChangeSpeedPanel (Shout3DApplet applet){
super(applet);
}
public void customInitialize() {
getRenderer().addRenderObserver(this, null);
addDeviceObserver(this,"MouseInput", null);
t = (Transform) getNodeByName("trans");
xPos = t.translation.getValue()[0];
}
protected void finalize() {
getRenderer().removeRenderObserver(this);
removeDeviceObserver(this,"MouseInput");
}
public boolean onDeviceInput(DeviceInput di, Object userData) {
MouseInput mi = (MouseInput) di;
switch (mi.which){
case MouseInput.DOWN:
pixelStartY = mi.y;
return true;
case MouseInput.UP:
speed = 0.0f;
return true;
case MouseInput.DRAG:
int pixelEndY = mi.y;
int dragDistanceY = pixelEndY - pixelStartY;
//convert drag to speed
//at 1 meter/second for each 70 pixels
speed = dragDistanceY/70f;
return true;
}//end of switch
return false;
}
public void onPreRender (Renderer r, Object o) {
float xDelta = speed/getFramesPerSecond();
xPos = xPos + xDelta;
t.translation.set1Value(0, xPos);
}
} //end of class